{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
      "To disable this warning, you can either:\n",
      "\t- Avoid using `tokenizers` before the fork if possible\n",
      "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API\n",
      "  warnings.warn(\"pkg_resources is deprecated as an API\", DeprecationWarning)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.logging')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "07/21/2023 11:29:32 PM root INFO: creating /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/__init__.py -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo\n",
      "07/21/2023 11:29:32 PM root INFO: creating /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/__pycache__/example_repo.cpython-310.pyc -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/__pycache__/test_workflow.cpython-310.pyc -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/__pycache__/__init__.cpython-310.pyc -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/test_workflow.py -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/feature_store.yaml -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/feature_repo/example_repo.py -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/feature_repo\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/bootstrap.py -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/__init__.py -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example\n",
      "07/21/2023 11:29:32 PM root INFO: creating /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/__pycache__/bootstrap.cpython-310.pyc -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/__pycache__/__init__.cpython-310.pyc -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example/__pycache__\n",
      "07/21/2023 11:29:32 PM root INFO: copying /Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/templates/local/README.md -> /Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example\n",
      "\n",
      "Creating a new Feast repository in \u001b[1m\u001b[32m/Users/mattsharp/projects/LLMs-in-Production/chapters/chapter_5/feast_example/feature_repo/feast_example/feature_repo/feast_example\u001b[0m.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# # Initialize feast feature store\n",
    "!feast init feast_example\n",
    "import os\n",
    "\n",
    "os.chdir(\"feast_example/feature_repo\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "Found cached dataset squad (/Users/mattsharp/.cache/huggingface/datasets/squad/plain_text/1.0.0/d6ec3ceb99ca480ce37cdd35555d6cb2511d223b9150cce08a837ef62ffea453)\n"
     ]
    }
   ],
   "source": [
    "# Download Question Answering dataset\n",
    "import pandas as pd\n",
    "from datasets import load_dataset\n",
    "import datetime\n",
    "\n",
    "from sentence_transformers import SentenceTransformer\n",
    "\n",
    "model = SentenceTransformer(\"all-MiniLM-L6-v2\")\n",
    "\n",
    "path = \"./data/qa.parquet\"\n",
    "\n",
    "\n",
    "def save_qa_to_parquet(path):\n",
    "    # Load SQuAD dataset\n",
    "    squad = load_dataset(\"squad\", split=\"train[:5000]\")\n",
    "    # Extract questions and answers\n",
    "    ids = squad[\"id\"]\n",
    "    questions = squad[\"question\"]\n",
    "    answers = [answer[\"text\"][0] for answer in squad[\"answers\"]]\n",
    "    # Create dataframe\n",
    "    qa = pd.DataFrame(\n",
    "        zip(ids, questions, answers),\n",
    "        columns=[\"question_id\", \"questions\", \"answers\"],\n",
    "    )\n",
    "    # Add embeddings and timestamps\n",
    "    qa[\"embeddings\"] = qa.questions.apply(lambda x: model.encode(x))\n",
    "    qa[\"created\"] = datetime.datetime.utcnow()\n",
    "    qa[\"datetime\"] = qa[\"created\"].dt.floor(\"h\")\n",
    "    # Save to parquet\n",
    "    qa.to_parquet(path)\n",
    "\n",
    "\n",
    "save_qa_to_parquet(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing ./qa.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile ./qa.py\n",
    "\n",
    "from feast import Entity, FeatureView, Field, FileSource, ValueType\n",
    "from feast.types import Array, Float32, String\n",
    "import os\n",
    "from datetime import timedelta\n",
    "\n",
    "path = './data/qa.parquet'\n",
    "\n",
    "question = Entity(name=\"question_id\", value_type=ValueType.STRING)\n",
    "\n",
    "question_feature = Field(\n",
    "    name=\"questions\",\n",
    "    dtype=String\n",
    ")\n",
    "\n",
    "answer_feature = Field(\n",
    "    name=\"answers\",\n",
    "    dtype=String\n",
    ")\n",
    "\n",
    "embedding_feature = Field(name=f\"embeddings\", dtype=Array(Float32))\n",
    "\n",
    "questions_view = FeatureView(\n",
    "    name=\"qa\",\n",
    "    entities=[question],\n",
    "    ttl=timedelta(days=1),\n",
    "    schema=[question_feature, answer_feature, embedding_feature],\n",
    "    source=FileSource(\n",
    "      path=path,\n",
    "      event_timestamp_column=\"datetime\",\n",
    "      created_timestamp_column=\"created\",\n",
    "      timestamp_field=\"datetime\",\n",
    "    ),\n",
    "    tags={},\n",
    "    online=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
      "To disable this warning, you can either:\n",
      "\t- Avoid using `tokenizers` before the fork if possible\n",
      "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API\n",
      "  warnings.warn(\"pkg_resources is deprecated as an API\", DeprecationWarning)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.logging')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/feature_store.py:561: RuntimeWarning: On demand feature view is an experimental feature. This API is stable, but the functionality does not scale well for offline retrieval\n",
      "  warnings.warn(\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/feast/infra/offline_stores/file_source.py:161: FutureWarning: 'ParquetDataset.schema' attribute is deprecated as of pyarrow 5.0.0 and will be removed in a future version. Specify 'use_legacy_dataset=False' while constructing the ParquetDataset, and then use the '.schema' attribute instead (which will return an Arrow schema instead of a Parquet schema).\n",
      "  schema = ParquetDataset(path).schema\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pandas/core/dtypes/cast.py:1641: DeprecationWarning: np.find_common_type is deprecated.  Please use `np.result_type` or `np.promote_types`.\n",
      "See https://numpy.org/devdocs/release/1.25.0-notes.html and the docs for more information.  (Deprecated NumPy 1.25)\n",
      "  return np.find_common_type(types, [])\n",
      "Created entity \u001b[1m\u001b[32mdriver\u001b[0m\n",
      "Created entity \u001b[1m\u001b[32mquestion_id\u001b[0m\n",
      "Created feature view \u001b[1m\u001b[32mdriver_hourly_stats_fresh\u001b[0m\n",
      "Created feature view \u001b[1m\u001b[32mqa\u001b[0m\n",
      "Created feature view \u001b[1m\u001b[32mdriver_hourly_stats\u001b[0m\n",
      "Created on demand feature view \u001b[1m\u001b[32mtransformed_conv_rate\u001b[0m\n",
      "Created on demand feature view \u001b[1m\u001b[32mtransformed_conv_rate_fresh\u001b[0m\n",
      "Created feature service \u001b[1m\u001b[32mdriver_activity_v1\u001b[0m\n",
      "Created feature service \u001b[1m\u001b[32mdriver_activity_v2\u001b[0m\n",
      "Created feature service \u001b[1m\u001b[32mdriver_activity_v3\u001b[0m\n",
      "\n",
      "Created sqlite table \u001b[1m\u001b[32mfeast_example_driver_hourly_stats_fresh\u001b[0m\n",
      "Created sqlite table \u001b[1m\u001b[32mfeast_example_driver_hourly_stats\u001b[0m\n",
      "Created sqlite table \u001b[1m\u001b[32mfeast_example_qa\u001b[0m\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Register the features\n",
    "!feast apply"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
      "To disable this warning, you can either:\n",
      "\t- Avoid using `tokenizers` before the fork if possible\n",
      "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API\n",
      "  warnings.warn(\"pkg_resources is deprecated as an API\", DeprecationWarning)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google.logging')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "/Users/mattsharp/miniconda3/envs/llmbook/lib/python3.10/site-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.\n",
      "Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages\n",
      "  declare_namespace(pkg)\n",
      "Materializing \u001b[1m\u001b[32m1\u001b[0m feature views to \u001b[1m\u001b[32m2023-11-29 17:00:00-07:00\u001b[0m into the \u001b[1m\u001b[32msqlite\u001b[0m online store.\n",
      "\n",
      "\u001b[1m\u001b[32mqa\u001b[0m from \u001b[1m\u001b[32m2023-07-21 05:28:39-06:00\u001b[0m to \u001b[1m\u001b[32m2023-11-29 17:00:00-07:00\u001b[0m:\n",
      "100%|████████████████████████████████████████████████████████| 5000/5000 [00:00<00:00, 11343.55it/s]\n"
     ]
    }
   ],
   "source": [
    "# Materialize the features (Don't forget to update the end date)\n",
    "!feast materialize-incremental 2023-11-30T00:00:00 --views qa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                question_id  \\\n",
      "0  5733be284776f41900661182   \n",
      "1  5733be284776f4190066117f   \n",
      "2  5733be284776f41900661180   \n",
      "3  5733be284776f41900661181   \n",
      "4  5733be284776f4190066117e   \n",
      "\n",
      "                                           questions  \\\n",
      "0  To whom did the Virgin Mary allegedly appear i...   \n",
      "1  What is in front of the Notre Dame Main Building?   \n",
      "2  The Basilica of the Sacred heart at Notre Dame...   \n",
      "3                  What is the Grotto at Notre Dame?   \n",
      "4  What sits on top of the Main Building at Notre...   \n",
      "\n",
      "                                          embeddings  \\\n",
      "0  [-0.018169419839978218, 0.05504932999610901, -...   \n",
      "1  [0.03145020082592964, 0.07019893825054169, 0.0...   \n",
      "2  [0.05156071484088898, 0.06941291689872742, 0.0...   \n",
      "3  [0.01869131810963154, 0.051365502178668976, 0....   \n",
      "4  [0.017544344067573547, 0.01992807164788246, 0....   \n",
      "\n",
      "                                   answers  \n",
      "0               Saint Bernadette Soubirous  \n",
      "1                a copper statue of Christ  \n",
      "2                        the Main Building  \n",
      "3  a Marian place of prayer and reflection  \n",
      "4       a golden statue of the Virgin Mary  \n"
     ]
    }
   ],
   "source": [
    "# Query the Feature Store\n",
    "from feast import FeatureStore\n",
    "\n",
    "store = FeatureStore(repo_path=\".\")\n",
    "\n",
    "ids = pd.read_parquet(path, columns=[\"question_id\"])\n",
    "\n",
    "feature_vectors = store.get_online_features(\n",
    "    features=[\"qa:questions\", \"qa:answers\", \"qa:embeddings\"],\n",
    "    entity_rows=[{\"question_id\": _id} for _id in ids.question_id.to_list()],\n",
    ").to_df()\n",
    "print(feature_vectors.head())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llmbook",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
